package com.ruihui.activity.exceprion;

import org.springframework.web.bind.MissingPathVariableException;
import org.springframework.web.bind.MissingServletRequestParameterException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;

import com.ruihui.activity.util.Result;
import com.ruihui.activity.util.ResultCode;



@RestControllerAdvice
public class AppGlobalExceptionHandler {

  @ExceptionHandler(MissingServletRequestParameterException.class)
  public Result handleMissingRequestParamsException() {
    return Result.failure(ResultCode.PARAM_NOT_COMPLETE);
  }

  @ExceptionHandler(MissingPathVariableException.class)
  public Result handlePathVariableParamsException() {
    return Result.failure(ResultCode.PARAM_NOT_COMPLETE);
  }

  @ExceptionHandler(MethodArgumentTypeMismatchException.class)
  public Result handleArgumentTypeMismatchException() {
    return Result.failure(ResultCode.PARAM_TYPE_BIND_ERROR);
  }
  @ExceptionHandler(ManualException.class)
  public Result handle(ManualException e) {
    return new Result(e.getCode(), e.getMessage());
  }
  @ExceptionHandler(IllegalArgumentException.class)
  public Result handle(IllegalArgumentException e) {
    return new Result(-1, e.getMessage());
  }
}
